package com.magicsoft.weitown.fragment;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.boyuan.huijiaoyu.R;
import com.magicsoft.app.adapter.CTHAdapter;
import com.magicsoft.app.entity.EmployeeRightsEntity;
import com.magicsoft.app.helper.StringUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

public class HomeMenuListAdapter extends CTHAdapter<EmployeeRightsEntity> {

	private DisplayImageOptions options;
	private ImageLoader imageLoader;

	public HomeMenuListAdapter(Context context,
			List<EmployeeRightsEntity> data, DisplayImageOptions options,
			ImageLoader imageLoader) {
		super(context, data);
		this.options = options;
		this.imageLoader = imageLoader;

		// badgeHelper = BadgeHelper.getBadgeHelper();
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		HolderViewStatic viewContent = null;
		EmployeeRightsEntity employeeRightsEntity = data.get(position);

		if (convertView == null) {
			viewContent = new HolderViewStatic();

			convertView = mInflater.inflate(R.layout.home_cardlist_item2, null);

			viewContent.iv_image = (ImageView) convertView
					.findViewById(R.id.iv_image);
			viewContent.tv_title = (TextView) convertView
					.findViewById(R.id.tv_title);
			viewContent.tv_content = (TextView) convertView
					.findViewById(R.id.tv_content);

			convertView.setTag(viewContent);
		} else {
			viewContent = (HolderViewStatic) convertView.getTag();
		}

		if (employeeRightsEntity != null) {

			String name = employeeRightsEntity.getName();

			viewContent.tv_title.setText(name);

			if (StringUtils.isImageUrl(employeeRightsEntity.getIcon()
					.getAndroid())) {
				imageLoader.displayImage(employeeRightsEntity.getIcon()
						.getAndroid(), viewContent.iv_image, options);
			}

		}
		return convertView;
	}

	static class HolderViewStatic {
		ImageView iv_image;
		TextView tv_title;// 标题
		TextView tv_content;// 内容
	}

}
